#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "ncfg.h"
#include "ipaddr.h"

#define DBG_LEVEL_NONE 0
#define DBG_LEVEL_ERROR 1
#define DBG_LEVEL_WARNING 2
#define DBG_LEVEL_INFO 3

#define DBG_INFO(slevel, fmt, ...) dbg_print(DBG_LEVEL_INFO, slevel, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DBG_WARNING(slevel, fmt, ...) dbg_print(DBG_LEVEL_WARNING, slevel, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DBG_ERROR(slevel, fmt, ...) dbg_print(DBG_LEVEL_ERROR, slevel, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)

#define DBG_STYLE_ERROR "\033[31m"
#define DBG_STYLE_WARNING "\033[33m"
#define DBG_STYLE_RESET "\033[0m"

#define DBG_ASSERT(expr)                                                                                               \
    {                                                                                                                  \
        if (!(expr))                                                                                                   \
        {                                                                                                              \
            dbg_print(DBG_LEVEL_ERROR, DBG_LEVEL_ERROR, __FILE__, __FUNCTION__, __LINE__, "ASSERT:%s failed!", #expr); \
            while (1)                                                                                                  \
            {                                                                                                          \
            }                                                                                                          \
        }                                                                                                              \
    }

void dbg_print(int level, int slevel, const char *file, const char *func, const int line, const char *fmt, ...);
void dbg_dump_hwaddr(const char *msg, const uint8_t *hwaddr, int len);
void dbg_dump_ipaddr(const char *msg, const struct _ipaddr_t *ipaddr);
void dbg_dump_hwaddr_oneline(const char *msg, const uint8_t *hwaddr, int len);
void dbg_dump_ipaddr_oneline(const char *msg, const struct _ipaddr_t *ipaddr);

#define DBG_DISP_ENABLED(module) ((module) >= DBG_LEVEL_INFO)

#endif